<!DOCTYPE html>
<html>
  <head>
    <meta charset="UTF-8" />
    <title>Document</title>
    <style></style>
  </head>
  <body>
    <div>常用的高阶函数</div>
    <script>
      //map
      const map = (array, fn) => {
        let results = [];
        for (let value of array) {
          results.push(fn(value));
        }
        return results;
      };
      let arr1 = [1, 3, 5, 7, 9];
      arr = map(arr1, (v) => v * v);
      console.log(arr);

      //every
      const every = (array, fn) => {
        let results = true;
        for (let value of array) {
          results = fn(value);
          if (!results) {
            break;
          }
        }
        return results;
      };
      let arr2 = [1, 2, 3, 4, 5, 6, 7, 8, 9];
      let r = every(arr2, (value) => value < 10);
      console.log(r);

      //some
      const some = (array, fn) => {
        let results = false;
        for (let value of array) {
          results = fn(value);
          if (results) {
            break;
          }
        }
        return results;
      };
      let arr3 = [1, 2, 3, 4, 5, 6, 7, 8, 9];
      let rr = some(arr3, (v) => v % 2 === 0);
      console.log(rr);
    </script>
  </body>
</html>
